package com.spareparts.activity;
import android.app.LocalActivityManager;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.spareparts.R;
import com.spareparts.activity.base.BaseActivityGroup;
import com.spareparts.util.Content;

public class WarehouseCKActivity extends BaseActivityGroup 
{
	private TextView mLibraryTextView;
	private TextView mRepairTextView;
	private TextView mScrapTextView;
	private TextView mBorrowTextView;
	
	private LinearLayout mContainer;
	private LocalActivityManager manager;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) 
	{
		requestWindowFeature( Window.FEATURE_NO_TITLE );
		
		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_warehouse_ck);

		mLibraryTextView = (TextView) findViewById(R.id.buttonLibrary);
		mRepairTextView = (TextView) findViewById(R.id.buttonRepair);
		mScrapTextView = (TextView) findViewById(R.id.buttonScrap);
		mBorrowTextView = (TextView) findViewById(R.id.buttonBorrow);
		
		mContainer = (LinearLayout) findViewById(R.id.container);
		manager=getLocalActivityManager();
		
		setTextViewOnClick();
		
		mCommonApplication.mContext = this;
		
		setIntent(Content.lIBRARY_CLICK);
		
		
	}
	
	
	/**
	 * 设置单击事件
	 */
	private void setTextViewOnClick()
	{
		
		mLibraryTextView.setOnClickListener(new OnClickListener() 
		{
			@Override
			public void onClick(View v) 
			{
				setIntent(Content.lIBRARY_CLICK);
			}
		});
		
		mRepairTextView.setOnClickListener(new OnClickListener() 
		{
			@Override
			public void onClick(View v) 
			{
				setIntent(Content.REPAIR_CHANGE_CLICK);
			}
		});
		
		mScrapTextView.setOnClickListener(new OnClickListener() 
		{
			@Override
			public void onClick(View v) 
			{
				setIntent(Content.SCRAP_CLICK);
			}
		});
		
		mBorrowTextView.setOnClickListener(new OnClickListener() 
		{
			@Override
			public void onClick(View v) 
			{
				setIntent(Content.BORROW_CLICK);
			}
		});
		
	}
	
	/**
	 * 设置跳转事件
	 */
	private void setIntent(int num)
	{
		 // 点击前所有的textview的状态设为没有点击
		 mLibraryTextView.setBackgroundResource(R.drawable.top_button_small);
		 mLibraryTextView.setTextColor(mContext.getResources().getColor(R.color.white));
		 mRepairTextView.setBackgroundResource(R.drawable.top_button_small);
		 mRepairTextView.setTextColor(mContext.getResources().getColor(R.color.white));
		 mScrapTextView.setBackgroundResource(R.drawable.top_button_small);
		 mScrapTextView.setTextColor(mContext.getResources().getColor(R.color.white));
		 mBorrowTextView.setBackgroundResource(R.drawable.top_button_small);
		 mBorrowTextView.setTextColor(mContext.getResources().getColor(R.color.white));
		
		 // 设置跳转
		 if(num == Content.lIBRARY_CLICK)
		 {
			 mContainer.removeAllViews();
			 mContainer.addView(manager.startActivity(
						"PAGE_1",
						new Intent(mContext, WareHouseStorageActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
						.putExtra("type", Content.lIBRARY_CLICK)).getDecorView());
			 
			 mLibraryTextView.setBackgroundResource(R.drawable.top_button_small_onclick);
			 mLibraryTextView.setTextColor(mContext.getResources().getColor(R.color.title_font_color));
		 }
		 else if(num == Content.REPAIR_CHANGE_CLICK)
		 {
			 mContainer.removeAllViews();
			 mContainer.addView(manager.startActivity(
						"PAGE_2",
						new Intent(mContext, WareHouseStorageActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
						.putExtra("type", Content.REPAIR_CHANGE_CLICK)).getDecorView());
			 
			 mRepairTextView.setBackgroundResource(R.drawable.top_button_small_onclick);
			 mRepairTextView.setTextColor(mContext.getResources().getColor(R.color.title_font_color));
		 }
		 else if(num == Content.SCRAP_CLICK)
		 {
			 mContainer.removeAllViews();
			 mContainer.addView(manager.startActivity(
						"PAGE_3",
						new Intent(mContext, WareHouseStorageActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
						.putExtra("type", Content.SCRAP_CLICK)).getDecorView());
			 
			 mScrapTextView.setBackgroundResource(R.drawable.top_button_small_onclick);
			 mScrapTextView.setTextColor(mContext.getResources().getColor(R.color.title_font_color));
		 }
		 else if(num == Content.BORROW_CLICK)
		 {
			 mContainer.removeAllViews();
			 mContainer.addView(manager.startActivity(
						"PAGE_4",
						new Intent(mContext, WareHouseStorageActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
						.putExtra("type", Content.BORROW_CLICK)).getDecorView());
			 
			 mBorrowTextView.setBackgroundResource(R.drawable.top_button_small_onclick);
			 mBorrowTextView.setTextColor(mContext.getResources().getColor(R.color.title_font_color));
		 }
	}
	
}
